#pragma once

#include <utility>

#include "..\OtlCore.h"

namespace Otl { namespace Sql
{
	class sql_handle final
	{
		friend class Connection;

	public:
		~sql_handle()
		{
			close();
		}

		sql_handle(sql_handle && other) _NOEXCEPT
			: m_handle{ std::move(other.m_handle) },
			  m_handleType{ std::move(m_handleType) }
		{
			other.m_handle = nullptr;
			m_handleType = 0;
		}

		sql_handle & operator=(sql_handle && other) _NOEXCEPT
		{
			m_handle = std::move(other.m_handle);
			m_handleType = std::move(m_handleType);

			other.m_handle = nullptr;
			m_handleType = 0;
		}

		sql_handle(const sql_handle &) = delete;
		sql_handle & operator=(const sql_handle &) = delete;

		_OTLCOREIMP
		void close();

		operator void*() const _NOEXCEPT
		{
			return m_handle;
		}

	private:
		sql_handle()
			: m_handle{ nullptr },
			  m_handleType{ 0 }
		{
		}

		explicit sql_handle(_In_ short handleType, const sql_handle & inputHandle = sql_handle{});

		void * m_handle;
		short m_handleType;
	};
}}